#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
struct S {
  int a, b;
};
S student[N];
long long sum[N];
bool cmp(S &x, S &y) { return x.a < y.a; }

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> student[i].a >> student[i].b;
  }
  int X;
  cin >> X;
  
  sort(student + 1, student + n + 1, cmp);

  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + student[i].b;
  }

  int R = 1, L = 1; // 确定两个指针的初始位置
  long long ans = 0;
  while (L <= n) { // 确定循环结束条件
    while (R <= n &&
           student[R].a - student[L].a <= X) { // 括号中填右指针移动的条件
      R++; // 移动右指针，并更新数值
    }
    // 根据题意确定更新答案的条件
    // 更新答案
    ans = max(ans, sum[R - 1] - sum[L - 1]);
    L++; // 移动左指针
  }
  cout << ans;
  return 0;
}